package api

import (
	"gitee.com/ling1314/origin-utility/constant"
	"gitee.com/ling1314/origin-utility/modules/service"
	"github.com/gin-gonic/gin"
)

type settingApi struct{}

func (a settingApi) SaveTopology(c *gin.Context) {
	input := struct {
		Content string `json:"content"`
	}{}
	if err := c.ShouldBindJSON(&input); err != nil {
		BadWithCode(c, constant.ParamsError)
		return
	}
	err := service.SettingService.SaveTopology(input.Content)
	if err != nil {
		BadWithError(c, err)
		return
	}
	Ok204(c)
}

func (a settingApi) GetTopology(c *gin.Context) {
	m, err := service.SettingService.GetTopology()
	if err != nil {
		BadWithError(c, err)
		return
	}
	Ok(c, m)
}
